package com.zhou.base.components.feign.cloud.controller;

import com.zhou.base.components.bs.common.model.Response;
import com.zhou.base.components.feign.cloud.feign.TestServiceNameFeign;
import com.zhou.base.components.feign.cloud.feign.TestUrlFeign;
import lombok.RequiredArgsConstructor;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试类
 *
 * @author xianfeng
 * @date 2023/11/22 16:21
 * @description:
 */
@RequiredArgsConstructor
@RefreshScope
@RestController
@RequestMapping("/testFeign")
public class TestFeignController {

    private final TestServiceNameFeign testServiceNameFeign;
    private final TestUrlFeign testUrlFeign;

    /**
     * 通过serviceName进行feign调用
     *
     * @return
     */
    @GetMapping("/feign1")
    public Response testWithServiceNameFeign() {
        Response<String> stringResponse = testServiceNameFeign.queryValue();
        return Response.success("testWithServiceNameFeign " + stringResponse.getData());
    }

    /**
     * 通过url进行feign调用
     *
     * @return
     */
    @GetMapping("/feign2")
    public Response testWithUrlFeign() {
        Response<String> stringResponse = testUrlFeign.queryValue();
        return Response.success("testWithUrlFeign " + stringResponse.getData());
    }

    @GetMapping("/404")
    public Response testQuery404() {
        Response<String> stringResponse = testUrlFeign.query404();
        return Response.success("testWithUrlFeign " + stringResponse.getData());
    }

    /**
     * 普通接口
     *
     * @return
     */
    @GetMapping("/getServerPort")
    public Response testLoadbalacce() {
        Response<Integer> serverPort = testServiceNameFeign.getServerPort();
        return Response.success(serverPort);
    }
}
